from django.db import models
from django.conf import settings
# Create your models here.


class Genome(models.Model):
    cn_name = models.CharField(max_length=200)
    en_name = models.CharField(max_length=200)
    latin_name = models.CharField(max_length=200)
    tag = models.CharField(unique=True, max_length=300)
    path = models.CharField(max_length=300)
    source = models.CharField(max_length=200)
    version = models.CharField(max_length=200)
    desc = models.TextField(blank=True)
    sub_time = models.DateTimeField(auto_now_add=True)
    last_update_time = models.DateTimeField(auto_now=True)
    submiter = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE)

    def __str__(self):
        return self.tag

    class Meta:
        ordering = ["sub_time"]

    def generate_desc(self):
        if not self.desc:
            desc = f"该参考基因组是{self.cn_name}的，它的版本是{self.version}，它的来源是{self.source}"

        return desc

    def show_abstract(self):
        return f"""
        English Name: {self.en_name}
        Chinese Name: {self.cn_name}
        Latin Name: {self.latin_name}
        """

    def save(self, *args, **kwargs):
        self.desc = self.generate_desc()
        super().save(*args, **kwargs)
